﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace Jy123.Web.Module.Club
{
    public class MyClub1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request.QueryString["Action"];
            if (string.IsNullOrEmpty(action))
            {
                action = context.Request["Action"];
            }
            if (!string.IsNullOrEmpty(action))
            {
                if (action.Equals("Formation"))
                {
                    //保存首发阵容
                    string strVId = context.Request["ClubId"].ToString();
                    string formation = context.Request["SelectedId"].ToString();
                    if (!string.IsNullOrEmpty(strVId))
                    {
                        int vId = int.Parse(strVId);
                        Jy123.BLL.Club_Main BLLClub = new Jy123.BLL.Club_Main();
                        Jy123.Model.Club_Main club = BLLClub.GetModel(vId);
                        club.Formation = formation;
                        BLLClub.Update(club);
                    }
                }
                else if (action.Equals("Form"))
                {
                    string strVId = context.Request["ClubId"].ToString();
                    string strForm = context.Request["SelectedId"].ToString();
                    if (!string.IsNullOrEmpty(strVId) && !string.IsNullOrEmpty(strForm))
                    {
                        int vId = int.Parse(strVId);
                        int formId = int.Parse(strForm);
                        Jy123.BLL.Club_Main BLLClub = new Jy123.BLL.Club_Main();
                        Jy123.Model.Club_Main club = BLLClub.GetModel(vId);
                        club.Form = formId;
                        BLLClub.Update(club);
                    }
                }
                else
                {
                    //进入赛场
                    string strVId = context.Request.QueryString["VenuesId"];
                    string strCId = context.Request.QueryString["ClubId"];
                    if (!string.IsNullOrEmpty(strVId) && !string.IsNullOrEmpty(strCId))
                    {
                        int vId = int.Parse(strVId);
                        int cId = int.Parse(strCId);
                        BLL.Club_Main BLLClub = new Jy123.BLL.Club_Main();
                        BLL.Venues_Main BLLVenues = new Jy123.BLL.Venues_Main();
                        Model.Club_Main club = BLLClub.GetModel(cId);
                        Model.Venues_Main venues = BLLVenues.GetModel(vId);
                        BLL.Race.Race BLLRace = new Jy123.BLL.Race.Race();
                        if (venues.VStatus != Convert.ToInt32(Jy123.BLL.Public.EnumConfig.VenuesStatus.Race))
                        {
                            BLLRace.JoinVenues(venues, club);
                        }
                        string strRedirect = "/Module/Venues/VenuesRace.aspx?VenuesId=" + venues.ID.ToString();
                        BLL.Public_JType BLLJType = new Jy123.BLL.Public_JType();
                        Model.Public_JType JType = BLLJType.GetModel(venues.FJType.Value);
                        if (JType.FSportType.Value == Convert.ToInt32(Jy123.BLL.Public.EnumConfig.SportType.Car) || JType.FSportType.Value == Convert.ToInt32(Jy123.BLL.Public.EnumConfig.SportType.F1))
                        {
                            strRedirect = "/Module/CarVenues/CarRace.aspx?VenuesId=" + venues.ID.ToString();
                        }
                        context.Response.Redirect(strRedirect);
                    }
                }
            }


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
